package com.gjh.xiaokabang2code.common;

import com.gjh.xiaokabang2code.model.request.VerifyRt;
import com.gjh.xiaokabang2code.model.response.LoginRs;
import com.gjh.xiaokabang2code.model.response.SafetyUserRs;
import com.gjh.xiaokabang2code.model.response.VerifyRs;
import lombok.Data;

import javax.servlet.http.HttpServletRequest;

import static com.gjh.xiaokabang2code.constant.UserConstant.USER_LOGIN_KEY;
import static com.gjh.xiaokabang2code.constant.UserConstant.USER_SAFETY_KEY;

@Data
public class HttpSessionUtil {
    private HttpServletRequest httpServletRequest;

    public static LoginRs getLoginUser(HttpServletRequest httpServletRequest) {
        Object attribute = httpServletRequest.getSession().getAttribute(USER_LOGIN_KEY);
        if (attribute == null) {
            return null;
        }
        return (LoginRs) attribute;
    }

    public static VerifyRs getSafetyUser(HttpServletRequest httpServletRequest) {
        Object attribute = httpServletRequest.getSession().getAttribute(USER_SAFETY_KEY);
        if (attribute == null) {
            return null;
        }
        return (VerifyRs) attribute;
    }
}